home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWSemEvt / Sources / FWScpPrp.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  12.0 KB  |  386 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSemPrp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSCPPRP_H
  11. #include "FWScpPrp.h"
  12. #endif
  13.  
  14. // ----- Framework Includes -----
  15.  
  16. #ifndef FWAPLEVT_H
  17. #include "FWAplEvt.h"
  18. #endif
  19.  
  20. #ifndef FWSCPTBL_H
  21. #include "FWScptbl.h"
  22. #endif
  23.  
  24. // ----- Foundation Includes -----
  25.  
  26. #ifndef FWPSTR_H
  27. #include "FWPStr.h"
  28. #endif
  29.  
  30. #ifndef __AEOBJECTS__
  31. #include <AEObjects.h>
  32. #endif
  33.  
  34. //========================================================================================
  35. //    Runtime Information
  36. //========================================================================================
  37.  
  38. #ifdef FW_BUILD_MAC    
  39. #pragma segment fwsemevt
  40. #endif
  41.  
  42. FW_DEFINE_AUTO(FW_CPropertyDesignator)
  43. FW_DEFINE_AUTO(FW_CSetPropertyCommand)
  44.  
  45. //========================================================================================
  46. //    class FW_CPropertyDesignator
  47. //========================================================================================
  48.  
  49. FW_DEFINE_CLASS_M1(FW_CPropertyDesignator, FW_MScriptable)
  50.  
  51. //---------------------------------------------------------------------------------------
  52. //    FW_CPropertyDesignator::FW_CPropertyDesignator
  53. //---------------------------------------------------------------------------------------
  54.  
  55. FW_CPropertyDesignator::FW_CPropertyDesignator(FW_CPart* part,
  56.                                             FW_MScriptable* whichObject,
  57.                                             ODDescType whichProperty) :
  58.     FW_MScriptable(),
  59.     fObject(whichObject),
  60.     fPart(part),
  61.     fWhichProperty(whichProperty),
  62.     fRefCount(1)
  63. {
  64.     FW_ASSERT(fPart);
  65.  
  66.     if (fObject)
  67.     {
  68.         fObject->AcquireScriptable();
  69.         whichObject->AddDependent(this);
  70.     }
  71.  
  72.     FW_END_CONSTRUCTOR
  73. }
  74.  
  75. //---------------------------------------------------------------------------------------
  76. //    FW_CPropertyDesignator::~FW_CPropertyDesignator
  77. //---------------------------------------------------------------------------------------
  78.  
  79. FW_CPropertyDesignator::~FW_CPropertyDesignator()
  80. {
  81.     FW_START_DESTRUCTOR
  82.     
  83.     FW_ASSERT(fRefCount == 0);
  84.     
  85.     if (fObject)
  86.     {
  87.         fObject->RemoveDependent(this);
  88.         fObject->ReleaseScriptable();
  89.     }
  90. }
  91.  
  92. //---------------------------------------------------------------------------------------
  93. //    FW_CPropertyDesignator::AcquireScriptable
  94. //---------------------------------------------------------------------------------------
  95.  
  96. long FW_CPropertyDesignator::AcquireScriptable()
  97. {
  98.     return ++fRefCount;
  99. }
  100.  
  101. //---------------------------------------------------------------------------------------
  102. //    FW_CPropertyDesignator::ReleaseScriptable
  103. //---------------------------------------------------------------------------------------
  104.  
  105. long FW_CPropertyDesignator::ReleaseScriptable()
  106. {
  107.     FW_ASSERT(fRefCount > 0);
  108.     
  109.     long result = --fRefCount;
  110.     
  111.     if (result == 0)
  112.         delete this;
  113.     
  114.     return result;
  115. }
  116.  
  117. //---------------------------------------------------------------------------------------
  118. //    FW_CPropertyDesignator::GetObjectClass
  119. //---------------------------------------------------------------------------------------
  120.  
  121. ODDescType FW_CPropertyDesignator::GetObjectClass() const
  122. {
  123.     return cProperty;
  124. }
  125.  
  126. //---------------------------------------------------------------------------------------
  127. //    FW_CPropertyDesignator::GetSpecifierForm
  128. //---------------------------------------------------------------------------------------
  129.  
  130. ODDescType FW_CPropertyDesignator::GetSpecifierForm() const
  131. {
  132.     return formPropertyID;
  133. }
  134.  
  135. //---------------------------------------------------------------------------------------
  136. //    FW_CPropertyDesignator::BuildObjectSpecifier
  137. //---------------------------------------------------------------------------------------
  138.  
  139. void FW_CPropertyDesignator::BuildObjectSpecifier(Environment* ev,
  140.                                                 FW_CPart* part,
  141.                                                 const FW_CFrame* frame,
  142.                                                 FW_CDesc& specifier,
  143.                                                 ODDescType preferredForm) const
  144. {
  145.     if (preferredForm != formPropertyID)
  146.     {
  147.         FW_MScriptable::BuildObjectSpecifier(ev, part, frame, specifier, preferredForm);
  148.     }
  149.     else
  150.     {
  151.         if (!fObject)
  152.             FW_THROW(FW_XException(errAEEventNotHandled));
  153.  
  154.         fObject->GetPropertySpecifier(ev, part, fWhichProperty, specifier);
  155.     }
  156. }
  157.  
  158. //---------------------------------------------------------------------------------------
  159. //    FW_CPropertyDesignator::GetTokenType
  160. //---------------------------------------------------------------------------------------
  161.  
  162. ODDescType FW_CPropertyDesignator::GetTokenType() const
  163. {
  164.     return typeODFPropertyDesignator;
  165. }
  166.  
  167. //---------------------------------------------------------------------------------------
  168. //    FW_CPropertyDesignator::GetPropertyValue
  169. //---------------------------------------------------------------------------------------
  170.  
  171. void FW_CPropertyDesignator::GetDesignateValue(Environment* ev, FW_CDesc& propertyValue) const
  172. {
  173.     if (!fObject)
  174.         FW_THROW(FW_XException(errAEEventNotHandled));
  175.         
  176.     fObject->GetProperty(ev, fPart, propertyValue, fWhichProperty, typeWildCard);
  177. }
  178.  
  179. //---------------------------------------------------------------------------------------
  180. //    FW_CPropertyDesignator::SetDesignateValue
  181. //---------------------------------------------------------------------------------------
  182.  
  183. void FW_CPropertyDesignator::SetDesignateValue(Environment* ev, FW_CDesc& propertyValue)
  184. {
  185.     if (!fObject)
  186.         FW_THROW(FW_XException(errAEEventNotHandled));
  187.  
  188.     fObject->SetProperty(ev, fPart, propertyValue, fWhichProperty);
  189. }
  190.  
  191. //---------------------------------------------------------------------------------------
  192. //    FW_CPropertyDesignator::RestoreDesignateValue
  193. //---------------------------------------------------------------------------------------
  194.  
  195. void FW_CPropertyDesignator::RestoreDesignateValue(Environment* ev, FW_CDesc& propertyValue)
  196. {
  197.     if (!fObject)
  198.         FW_THROW(FW_XException(errAEEventNotHandled));
  199.     fObject->RestoreProperty(ev, fPart, propertyValue, fWhichProperty);
  200. }
  201.  
  202. //---------------------------------------------------------------------------------------
  203. //    FW_CPropertyDesignator::GetDesignateFrame
  204. //---------------------------------------------------------------------------------------
  205.  
  206. FW_CFrame* FW_CPropertyDesignator::GetDesignateFrame(Environment* ev, FW_CPart* part)
  207. {
  208.     if (!fObject)
  209.         FW_THROW(FW_XException(errAEEventNotHandled));
  210.     return (fObject->GetFrame(ev, part));
  211. }
  212.  
  213. //---------------------------------------------------------------------------------------
  214. //    FW_CPropertyDesignator::GetDesignateInfo
  215. //---------------------------------------------------------------------------------------
  216.  
  217. void FW_CPropertyDesignator::GetDesignateInfo(Environment* ev,
  218.                                             FW_Boolean& canUndo,
  219.                                             FW_Boolean& causesChange)
  220. {
  221.     if (!fObject)
  222.         FW_THROW(FW_XException(errAEEventNotHandled));
  223.     fObject->GetPropertyInfo(ev, fPart, canUndo, causesChange);
  224. }
  225.  
  226. //---------------------------------------------------------------------------------------
  227. //    FW_CPropertyDesignator::GetDesignateUndoStrings
  228. //---------------------------------------------------------------------------------------
  229.  
  230. void FW_CPropertyDesignator::GetDesignateUndoStrings(Environment* ev,
  231.                                                     FW_CPart* part,
  232.                                                     FW_CString& undoString,
  233.                                                     FW_CString& redoString)
  234. {
  235.     if (!fObject)
  236.         FW_THROW(FW_XException(errAEEventNotHandled));
  237.     fObject->GetUndoStrings(ev, part, fWhichProperty, undoString, redoString);
  238. }
  239.  
  240. //---------------------------------------------------------------------------------------
  241. //    FW_CPropertyDesignator::HandlePrimaryDeleted
  242. //---------------------------------------------------------------------------------------
  243.  
  244. void FW_CPropertyDesignator::HandlePrimaryDeleted(FW_MScriptable* primary)
  245. {
  246. FW_UNUSED(primary);
  247.  
  248.     FW_ASSERT(primary == fObject);
  249.     fObject = NULL;
  250. }
  251.  
  252. //---------------------------------------------------------------------------------------
  253. //    FW_CPropertyDesignator::Compare
  254. //---------------------------------------------------------------------------------------
  255.  
  256. FW_Boolean FW_CPropertyDesignator::CompareScriptableObjects(Environment* ev,
  257.                                                             FW_CPart* part,
  258.                                                             ODDescType operation,
  259.                                                             const FW_CDesc& other) const
  260. {
  261. FW_UNUSED(part);
  262.     FW_CDesc value;
  263.  
  264.     GetDesignateValue(ev, value);
  265.     return value.Compare(operation, other);
  266. }
  267.  
  268. //---------------------------------------------------------------------------------------
  269. //    FW_CPropertyDesignator::DoAEGetData
  270. //---------------------------------------------------------------------------------------
  271.  
  272. void FW_CPropertyDesignator::DoAEGetData(Environment* ev,
  273.                                         FW_CPart* part,
  274.                                         const FW_CAppleEvent& event,
  275.                                         FW_CAppleEvent& reply)
  276. {
  277. FW_UNUSED(part);
  278.     FW_CDesc    propertyValue;
  279.     ODDescType     desiredType = typeWildCard;
  280.     
  281.     if (event.HasDataKey(keyAERequestedType))
  282.     {
  283.         Size actualSize;
  284.         event.GetDataByPtr(typeWildCard, &desiredType, actualSize, sizeof(ODDescType), keyAERequestedType);
  285.     }
  286.  
  287.     GetDesignateValue(ev, propertyValue);
  288.     reply.PutDataByDesc(propertyValue, keyAEResult);
  289. }
  290.  
  291. //---------------------------------------------------------------------------------------
  292. //    FW_CPropertyDesignator::DoAESetData
  293. //---------------------------------------------------------------------------------------
  294.  
  295. void FW_CPropertyDesignator::DoAESetData(Environment* ev,
  296.                                         FW_CPart* part,
  297.                                         const FW_CAppleEvent& event,
  298.                                         FW_CAppleEvent& reply)
  299. {
  300. FW_UNUSED(reply);
  301.     FW_CDesc     propertyValue;
  302.  
  303.     FW_Boolean canUndo;
  304.     FW_Boolean causesChange;
  305.     
  306.     event.GetDataByDesc(propertyValue, keyAEData);
  307.     GetDesignateInfo(ev, canUndo, causesChange);
  308.     
  309.     FW_CSetPropertyCommand* cmd = FW_NEW(FW_CSetPropertyCommand, (ev, GetDesignateFrame(ev, part), canUndo, this, propertyValue));
  310.     cmd->SetCausesChange(ev, causesChange);        
  311.     cmd->Execute(ev);
  312. }
  313.  
  314. //========================================================================================
  315. //    class FW_SetPropertyCommand
  316. //========================================================================================
  317.  
  318. //---------------------------------------------------------------------------------------
  319. //    FW_CSetPropertyCommand::SetPropertyCommand
  320. //---------------------------------------------------------------------------------------
  321.  
  322. FW_CSetPropertyCommand::FW_CSetPropertyCommand(Environment* ev,
  323.                                             FW_CFrame* frame,
  324.                                             FW_Boolean canUndo,
  325.                                             FW_CPropertyDesignator* propDesignator,
  326.                                             FW_CDesc& newValue) :
  327.     FW_CCommand(ev, -1, frame, TRUE),
  328.     fPropDesignator(propDesignator),
  329.     fOldValue(),
  330.     fNewValue(newValue)
  331. {
  332. FW_UNUSED(canUndo);
  333.     if (propDesignator)
  334.         propDesignator->AcquireScriptable();
  335.         
  336.     FW_END_CONSTRUCTOR
  337. }
  338.  
  339. //---------------------------------------------------------------------------------------
  340. //    FW_CSetPropertyCommand::~SetPropertyCommand
  341. //---------------------------------------------------------------------------------------
  342.  
  343. FW_CSetPropertyCommand::~FW_CSetPropertyCommand()
  344. {
  345.     FW_START_DESTRUCTOR
  346.     
  347.     if (fPropDesignator)
  348.         fPropDesignator->ReleaseScriptable();
  349. }
  350.  
  351. //---------------------------------------------------------------------------------------
  352. //    FW_CSetPropertyCommand::DoIt
  353. //---------------------------------------------------------------------------------------
  354.  
  355. void FW_CSetPropertyCommand::DoIt(Environment* ev)
  356. {
  357.     if (GetCanUndo(ev))
  358.     {
  359.         FW_CString    undoString;
  360.         FW_CString    redoString;
  361.         
  362.         fPropDesignator->GetDesignateUndoStrings(ev, GetPart(ev), undoString, redoString);
  363.         SetMenuStrings(ev, undoString, redoString);
  364.     }
  365.  
  366.     fPropDesignator->GetDesignateValue(ev, fOldValue);
  367.     fPropDesignator->SetDesignateValue(ev, fNewValue);
  368. }
  369.  
  370. //---------------------------------------------------------------------------------------
  371. //    FW_CSetPropertyCommand::UndoIt
  372. //---------------------------------------------------------------------------------------
  373.  
  374. void FW_CSetPropertyCommand::UndoIt(Environment* ev)
  375. {
  376.     fPropDesignator->RestoreDesignateValue(ev, fOldValue);
  377. }
  378.  
  379. //---------------------------------------------------------------------------------------
  380. //    FW_CSetPropertyCommand::RedoIt
  381. //---------------------------------------------------------------------------------------
  382.  
  383. void FW_CSetPropertyCommand::RedoIt(Environment* ev)
  384. {
  385.     fPropDesignator->SetDesignateValue(ev, fNewValue);
  386. }